package cn.dankal.lequ.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.dankal.lequ.R;
import cn.dankal.lequ.commom.adapter.FragmentAdapter;
import cn.dankal.lequ.commom.util.Constant;
import cn.dankal.lequ.ui.fragment.gamedetails_fragment.Comment_Fragment;
import cn.dankal.lequ.ui.fragment.gamedetails_fragment.Details_Fragment;
import cn.dankal.lequ.ui.fragment.gamedetails_fragment.Gift_Fragment;
import cn.dankal.lequ.ui.fragment.gamedetails_fragment.Recommend_Fragment;
import cn.dankal.lequ.ui.fragment.gamedetails_fragment.Video_Fragment;

/**
 * 作者： fred on 16/4/18 16:46.
 * 邮箱：fred_kang@dankal.cn
 */

public class GameDetailsActivity extends AppCompatActivity {
    @Bind(R.id.tab_layout)
    TabLayout tab_layout;
    @Bind(R.id.view_pager)
    ViewPager view_pager;
    @Bind(R.id.app_install)
    Button appInstall;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gamedetails);
        ButterKnife.bind(this);
        initTabLayout();

    }

    @OnClick({R.id.bt_back, R.id.all_buluo,R.id.app_install})
    public void onclick(View view) {

        switch (view.getId()) {
            case R.id.bt_back:
                this.finish();
                break;
            case R.id.all_buluo:
                startActivity(new Intent(GameDetailsActivity.this, BuLuoActivity.class));
                break;
            case R.id.app_install:

                break;
        }
    }

//    private void downLoad() {
//        ThreadPoolFactory.getDownLoadPool().execute(new DownLoadTa);
//    }

    private void initTabLayout() {
        List<Fragment> fragments = new ArrayList<>();
        ArrayList<String> tablayout_titles = new ArrayList<>();
        tablayout_titles.add(Constant.DETAILS);
        fragments.add(new Details_Fragment());
        tablayout_titles.add(Constant.COMMENT);
        fragments.add(new Comment_Fragment());
        tablayout_titles.add(Constant.VIDEO);
        fragments.add(new Video_Fragment());
        tablayout_titles.add(Constant.GIFT);
        fragments.add(new Gift_Fragment());
        tablayout_titles.add(Constant.RECOMMEND);
        fragments.add(new Recommend_Fragment());
        for (int i = 0; i < tablayout_titles.size(); i++) {
            tab_layout.addTab(tab_layout.newTab().setText(tablayout_titles.get(i)));
        }
        FragmentAdapter adapter = new FragmentAdapter(this.getSupportFragmentManager(), fragments, tablayout_titles);
        view_pager.setAdapter(adapter);
        tab_layout.setupWithViewPager(view_pager);
        tab_layout.setTabsFromPagerAdapter(adapter);
    }
}
